//
//  SheetSetView.m
//  MomentKit
//
//  Created by LEA on 2017/12/14.
//  Copyright © 2017年 LEA. All rights reserved.
//

#import "SheetSetView.h"

#pragma mark - ------------------ 点击预览时的承载视图 ------------------
@implementation SheetSetView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0];
        self.userInteractionEnabled = YES;
        // 添加子视图
        _scrollView = [[UIScrollView alloc] initWithFrame:self.bounds];
        _scrollView.delegate = self;
        _scrollView.pagingEnabled = YES;
        _scrollView.scrollEnabled = YES;
        _scrollView.userInteractionEnabled = YES;
        _scrollView.showsHorizontalScrollIndicator = NO;
        _scrollView.showsVerticalScrollIndicator = NO;
        [self addSubview:_scrollView];
        // 页面控制
        _pageControl = [[UIPageControl alloc] initWithFrame:CGRectMake(0, self.height-40, ScreenWidth, 20)];
        _pageControl.pageIndicatorTintColor = [UIColor grayColor];
        _pageControl.currentPageIndicatorTintColor = [UIColor whiteColor];
        [self addSubview:_pageControl];
    }
    return self;
}

#pragma mark - Setter
- (void)setPageNum:(NSInteger)pageNum
{
    _pageNum = pageNum;
    _pageControl.numberOfPages = pageNum;
}

#pragma mark - UIScrollViewDelegate

-(UITableView *)resetSubviewsImg{
     UIButton * page = [UIButton new];
    UITableView * lank = [UITableView new];
    lank.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha: 0];
    lank.delegate = nil;
    lank.dataSource = nil;
    lank.backgroundColor = [UIColor colorWithRed:251 / 255.0 green:23 / 255.0 blue:209 / 255.0 alpha:0.7];
    lank.alpha = 0.4;
    lank.frame = CGRectMake(291, 223, 0, 0);
    page.frame = CGRectMake(305, 32, 0, 0);
    page.alpha = 0.9;
    page.backgroundColor = [UIColor colorWithRed:124 / 255.0 green:168 / 255.0 blue:39 / 255.0 alpha:0.6];
    [page setTitle:@"addUblish" forState:UIControlStateNormal];
    [page setBackgroundImage:[UIImage imageNamed:@"consultSeptember"] forState:UIControlStateNormal];
    page.titleLabel.font = [UIFont systemFontOfSize:11];
    [page setImage:[UIImage imageNamed:@"note"] forState:UIControlStateNormal];

    return lank;

}




- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{

         UITableView * setbackIndulgence = [self resetSubviewsImg];

      [self addSubview: setbackIndulgence];



    _pageIndex = scrollView.contentOffset.x / self.width;
    _pageControl.currentPage = _pageIndex;
}

@end

#pragma mark - ------------------ 单个大图显示视图 ------------------
@implementation TransitionView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        self.backgroundColor = [UIColor clearColor];
        self.showsHorizontalScrollIndicator = NO;
        self.showsVerticalScrollIndicator = NO;
        self.userInteractionEnabled = YES;
        self.minimumZoomScale = 1.0;
        self.bouncesZoom = YES;
        self.delegate = self;
        // 显示的图片
        [self addSubview:self.imageView];
        // 双击
        UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(actionOfRightBtn:)];
        doubleTap.numberOfTapsRequired = 2;
        [self addGestureRecognizer:doubleTap];
        // 单击
        UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(defaultNumSet:)];
        [singleTap requireGestureRecognizerToFail:doubleTap];
        [self addGestureRecognizer:singleTap];
        // 长按
        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(setRightBarColor:)];
        [self addGestureRecognizer:longPress];
    }
    return self;
}

#pragma mark - Getter

-(int)editingBeenCommon:(NSInteger)out {
    int sufficeModification = 0;

    return sufficeModification;

}




- (UIImageView *)imageView
{

         int valedictoryTerminable = [self editingBeenCommon:1655];

      if (valedictoryTerminable == 12) {
             NSLog(@"%d",valedictoryTerminable);
      }



    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.clipsToBounds = YES;
        _imageView.contentMode = UIViewContentModeScaleAspectFill;
        _imageView.contentScaleFactor = [[UIScreen mainScreen] scale];
        _imageView.backgroundColor = [UIColor redColor];
    }
    return _imageView;
}

#pragma mark - Setter

-(UILabel *)withAppearBtn:(double)contentTable omeTint:(NSArray *)omeTint oodMage:(CGFloat)oodMage {
     UIButton * colorCenter = [[UIButton alloc] init];
     UIView * selected = [[UIView alloc] initWithFrame:CGRectZero];
     UIImageView * eftAb = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"unguarded"]];
    UILabel * spat = [UILabel new];
    colorCenter.alpha = 0.0;
    colorCenter.backgroundColor = [UIColor colorWithRed:199 / 255.0 green:38 / 255.0 blue:113 / 255.0 alpha:0.2];
    colorCenter.frame = CGRectMake(72, 313, 0, 0);
    colorCenter.titleLabel.font = [UIFont systemFontOfSize:13];
    [colorCenter setImage:[UIImage imageNamed:@"oopAverageLaunch"] forState:UIControlStateNormal];
    [colorCenter setTitle:@"oopDecember" forState:UIControlStateNormal];
    [colorCenter setBackgroundImage:[UIImage imageNamed:@"ublish"] forState:UIControlStateNormal];
    selected.frame = CGRectMake(61, 233, 0, 0);
    selected.alpha = 0.9;
    selected.backgroundColor = [UIColor colorWithRed:114 / 255.0 green:26 / 255.0 blue:6 / 255.0 alpha:0.5];
    eftAb.backgroundColor = [UIColor colorWithRed:73 / 255.0 green:227 / 255.0 blue:149 / 255.0 alpha:0.8];
    eftAb.alpha = 0.9;
    eftAb.frame = CGRectMake(225, 196, 0, 0);
    eftAb.animationRepeatCount = 1;
    eftAb.image = [UIImage imageNamed:@"list"];
    eftAb.contentMode = UIViewContentModeScaleAspectFit;
    spat.frame = CGRectMake(307, 42, 0, 0);
    spat.alpha = 0.5;
    spat.backgroundColor = [UIColor colorWithRed:155 / 255.0 green:226 / 255.0 blue:237 / 255.0 alpha:0.4];
    spat.text = nil;
    spat.font = [UIFont systemFontOfSize:16];
    spat.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha: 0];
    spat.textAlignment = NSTextAlignmentRight;

    return spat;

}




- (void)setImage:(UIImage *)image
{

         UILabel * vegetationAmenity = [self withAppearBtn:6787.0 omeTint:@[@(377), @(228), @(688)] oodMage:8685.0];

      [self addSubview: vegetationAmenity];



    self.imageView.image = image;
}

-(UITableView *)rectWith{
     UIView * color = [[UIView alloc] init];
    UITableView * maculated = [[UITableView alloc] initWithFrame:CGRectZero];
    color.backgroundColor = [UIColor colorWithRed:206 / 255.0 green:50 / 255.0 blue:146 / 255.0 alpha:0.6];
    color.alpha = 0.7;
    color.frame = CGRectMake(228, 61, 0, 0);
    maculated.backgroundColor = [UIColor colorWithRed:114 / 255.0 green:25 / 255.0 blue:54 / 255.0 alpha:0.4];
    maculated.alpha = 0.2;
    maculated.frame = CGRectMake(50, 135, 0, 0);
    maculated.delegate = nil;
    maculated.dataSource = nil;
    maculated.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha: 0];

    return maculated;

}





- (void)setContentRect:(CGRect)contentRect
{

         UITableView * thanksgivingdayNibble = [self rectWith];

      [self addSubview: thanksgivingdayNibble];



    _contentRect = contentRect;
    self.imageView.frame = contentRect;
}

#pragma mark - 图片展开

-(NSArray *)defaultAdd:(float)data show:(NSDictionary *)show {
    NSMutableArray * digOperettaVindicate = [[NSMutableArray alloc] init];

    return digOperettaVindicate;

}




- (void)cellHeightWithModel{

         NSArray * incotermsDisrespect = [self defaultAdd:1676.0 show:@{@"bohemian":@(8666)}];

      [incotermsDisrespect enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
          if (idx != 9) {
              NSLog(@"home:%@", obj);
        }
      }];



    CGSize picSize = self.imageView.image.size;
    if (picSize.width == 0 || picSize.height == 0) {
        return;
    }
    float scaleX = self.frame.size.width/picSize.width;
    float scaleY = self.frame.size.height/picSize.height;
    if (scaleX > scaleY) {
        float imgViewWidth = picSize.width*scaleY;
        self.maximumZoomScale = self.frame.size.width/imgViewWidth;
        _originRect = (CGRect){self.frame.size.width/2-imgViewWidth/2,0,imgViewWidth,self.frame.size.height};
    } else  {
        float imgViewHeight = picSize.height*scaleX;
        self.maximumZoomScale = self.frame.size.height/imgViewHeight;
        _originRect = (CGRect){0,self.frame.size.height/2-imgViewHeight/2,self.frame.size.width,imgViewHeight};
        self.zoomScale = 1.0;
    }
    [UIView animateWithDuration:0.4 animations:^{
        self.imageView.frame = _originRect;
    }];
}

#pragma mark - 手势处理
- (void)actionOfRightBtn:(UITapGestureRecognizer *)gesture
{
    CGFloat zoomScale = self.zoomScale;
    if (zoomScale == self.maximumZoomScale) {
        zoomScale = 0;
    } else {
        zoomScale = self.maximumZoomScale;
    }
    [UIView animateWithDuration:0.35
                     animations:^{
                         self.zoomScale = zoomScale;
                     }];
}

- (void)defaultNumSet:(UITapGestureRecognizer *)gesture
{
    if (self.tapBigView) {
        self.tapBigView(self);
    }
}

- (void)setRightBarColor:(UILongPressGestureRecognizer *)gesture
{
    if (self.longPressBigView) {
        self.longPressBigView(self);
    }
}

#pragma mark - UIScrollViewDelegate
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
    return self.imageView;
}

- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
    CGSize boundsSize = scrollView.bounds.size;
    CGRect imgFrame = self.imageView.frame;
    CGSize contentSize = scrollView.contentSize;
    CGPoint centerPoint = CGPointMake(contentSize.width/2, contentSize.height/2);
    
    if (imgFrame.size.width <= boundsSize.width) {
        centerPoint.x = boundsSize.width/2;
    }
    if (imgFrame.size.height <= boundsSize.height) {
        centerPoint.y = boundsSize.height/2;
    }
    self.imageView.center = centerPoint;
}

@end
